<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include2923 :: header('工程概算台账列表')"/>
</head>
<body class="pear-container">
<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">工程编号</label>
                <div class="layui-input-inline">
                    <input type="text" name="pronum" placeholder="" class="layui-input">
                </div>
                <label class="layui-form-label">工程名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="proname" placeholder="" class="layui-input">
                </div>
                <label class="layui-form-label">工程类别</label>
                <div class="layui-input-inline">
                    <select name="type" lay-filter="aihao">
                        <option value=""></option>
                        <option value="1">基建类</option>
                        <option value="2">业扩类</option>
                        <option value="3">技改类</option>
                        <option value="4">大修类</option>
                    </select>
                </div>
                <label class="layui-form-label">批次号</label>
                <div class="layui-input-inline">
                    <input type="text" name="batchnum" placeholder="" class="layui-input">
                </div>
                <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit
                        lay-filter="infoProjectbudgetJs-query">
                    <i class="layui-icon layui-icon-search"></i>
                    查询
                </button>
                <button type="reset" class="pear-btn pear-btn-md">
                    <i class="layui-icon layui-icon-refresh"></i>
                    重置
                </button>
            </div>
        </form>
    </div>
</div>
<div class="layui-card">
    <div class="layui-card-body">
        <table id="infoProjectbudgetJs-table" lay-filter="infoProjectbudgetJs-table"></table>
    </div>
</div>
</body>

<script type="text/html" id="infoProjectbudgetJs-toolbar">
<!--    <button class="pear-btn pear-btn-warming pear-btn-md"-->
<!--            id="uploadFile">-->
<!--        <i class="layui-icon layui-icon-add-1"></i>-->
<!--        基建类工程导入-->
<!--    </button>-->
<!--    &lt;!&ndash;    <button class="pear-btn pear-btn-warming pear-btn-md"&ndash;&gt;-->
<!--    &lt;!&ndash;            id="uploadFileYk">&ndash;&gt;-->
<!--    &lt;!&ndash;        <i class="layui-icon layui-icon-add-1"></i>&ndash;&gt;-->
<!--    &lt;!&ndash;        业扩类工程导入&ndash;&gt;-->
<!--    &lt;!&ndash;    </button>&ndash;&gt;-->
<!--    <button shiro:hasPermission="info:infoProjectbudgetJs:add" class="pear-btn pear-btn-primary pear-btn-md"-->
<!--            lay-event="add">-->
<!--        <i class="layui-icon layui-icon-add-1"></i>-->
<!--        手动新增-->
<!--    </button>-->
<!--    <button class="pear-btn pear-btn-primary pear-btn-md"-->
<!--            lay-event="import">-->
<!--        <i class="layui-icon layui-icon-add-1"></i>-->
<!--        确认入库-->
<!--    </button>-->
<!--    <button shiro:hasPermission="info:infoProjectbudgetJs:remove" class="pear-btn pear-btn-danger pear-btn-md"-->
<!--            lay-event="batchRemove">-->
<!--        <i class="layui-icon layui-icon-delete"></i>-->
<!--        删除-->
<!--    </button>-->
    <button class="pear-btn pear-btn-md pear-btn-warming"
            lay-filter="export" lay-submit type="button">
        <i class="layui-icon layui-icon-export"></i>
        导出
    </button>
</script>

<script type="text/html" id="infoProjectbudgetJs-bar">
    <button shiro:hasPermission="info:infoProjectbudgetJs:edit" class="pear-btn pear-btn-warming pear-btn-sm"
            lay-event="edit" title="修改"><i class="layui-icon layui-icon-edit"></i>
    </button>

<!--    <button shiro:hasPermission="info:infoProjectbudgetJs:remove" class="pear-btn pear-btn-danger pear-btn-sm"-->
<!--            lay-event="remove" title="删除"><i class="layui-icon layui-icon-delete"></i>-->
<!--    </button>-->
</script>

<script type="text/html" id="infoProjectbudgetJsfile-bar">
    <!--    <button shiro:hasPermission="gen:monthEvaluation:edit" class="pear-btn pear-btn-primary pear-btn-sm"-->
    <!--            lay-event="edit" title="修改"><i class="layui-icon layui-icon-edit"></i>-->
    <!--    </button>-->

    <!--    <button shiro:hasPermission="gen:monthEvaluation:remove" class="pear-btn pear-btn-danger pear-btn-sm"-->
    <!--            lay-event="remove" title="删除"><i class="layui-icon layui-icon-delete"></i>-->
    <!--    </button>-->
    <button class="pear-btn pear-btn-primary pear-btn-sm"
            lay-event="" title="概算书PDF预览" onclick="materialStencils('{{d.id}}')"><i
            class="layui-icon layui-icon-template-1"></i>
        预览
    </button>
    <button class="pear-btn pear-btn-primary pear-btn-sm"
            lay-event="" title="概算书下载" onclick="downloadExcel('{{d.id}}')"><i
            class="layui-icon layui-icon-template-1"></i>
        下载
    </button>
<!--    <button class="pear-btn pear-btn-primary pear-btn-sm"-->
<!--            lay-event="" title="手动新增补传附件" onclick="uploadExcel('{{d.createtype}}' ,'{{d.id}}')"><i-->
<!--            class="layui-icon layui-icon-template-1"></i>-->
<!--        上传-->
<!--    </button>-->
<!--    <button class="pear-btn pear-btn-warming pear-btn-sm"-->
<!--            lay-event="findAuditPlan">-->
<!--        查看审核进度-->
<!--    </button>-->
<!--    <button class="pear-btn pear-btn-primary pear-btn-sm"-->
<!--            lay-event="findResult">-->
<!--        查看实时结果-->
<!--    </button>-->
</script>

<script type="text/html" id="infoProjectbudgetJs-type">
    {{#if (d.dataState == '0') { }}
    <span class="layui-badge layui-bg-orange">开启</span>
    {{# }else if(d.dataState == '-1'){ }}
    <span class="layui-badge layui-bg-blue">关闭</span>
    {{# } }}
</script>

<th:block th:include="include2923 :: footer"/>
<script>
    layui.use(['table', 'form', 'jquery','upload'], function () {
        var table = layui.table;
        var form = layui.form;
        var $ = layui.jquery;
        var upload = layui.upload;

        var MODULE_PATH = rootPath + "/InfoProjectbudgetJsController/";
        var MODULE_PATH_FILE = rootPath + "/InfoFileController/";

        var cols = [
            [
                {type: 'checkbox', fixed: 'left'},

                // {title: 'ID', field: 'id', align: 'center'},

                {title: '工程编码', field: 'pronum', align: 'center', width: 200, fixed: 'left'},

                {title: '工程名称', field: 'proname', align: 'center',width:450, fixed: 'left'},

                {
                    title: '工程类别', field: 'type', align: 'center', width: 150, templet: function (res) {
                        if (res.type == '1') {
                            return '基建类';
                        } else if (res.type == '2') {
                            return '业扩类';
                        } else if (res.type == '3') {
                            return '技改类';
                        } else if (res.type == '4') {
                            return '大修类';
                        }else {
                            return '';
                        }
                    }
                },


                {title: '概算书日期', field: 'bookdate', align: 'center',width:150},

                {title: '批次', field: 'batchnum', align: 'center', width: 200},

                {title: '建筑工程费(元)', field: 'jzgcf', align: 'center',width:200},

                {title: '安装工程费(元)', field: 'azgcf', align: 'center',width:200},

                {title: '设备购置费(元)', field: 'sbgzf', align: 'center',width:200},

                {title: '其他费(元)', field: 'qtf', align: 'center',width:200},

                {title: '总投资(元)', field: 'total', align: 'center',width:200},

                {title: '建设场地征用及清理费(元)', field: 'jscdzyjglf', align: 'center',width:200},

                {title: '项目建设管理费(元)', field: 'xmjsglf', align: 'center',width:200},

                {title: '建设期贷款利息(元)', field: 'jsqdklx', align: 'center',width:200},

                {title: '项目管理经费(元)', field: 'xmgljf', align: 'center',width:200},

                {title: '工程监理费(元)', field: 'gcjlf', align: 'center',width:200},

                {title: '施工费(元)', field: 'sgf', align: 'center',width:200},

                {title: '项目前期工作费(元)', field: 'xmqqgzf', align: 'center',width:200},

                {title: '勘察费(元)', field: 'kcf', align: 'center',width:200},

                {title: '设计费(元)', field: 'sjf', align: 'center',width:200},

                {title: '设计文件评审费(元)', field: 'sjwjpsf', align: 'center',width:200},

                {title: '项目后评价费(元)', field: 'xmhpjf', align: 'center',width:200},

                {title: '工程保险费(元)', field: 'gcbxf', align: 'center', width: 200},

                {title: '施工过程造价咨询及竣工结算审核费(元)', field: 'jgjsshf', align: 'center', width: 300},

                {title: '生产准备费(元)', field: 'sczbf', align: 'center', width: 200},

                {title: '带电作业(元)', field: 'ddzyf', align: 'center', width: 200},

                {title: '创建类别', field: 'createtype',width:200, align: 'center',templet: function (res) {
                        if (res.createtype == '1') {
                            return '导入';
                        } else {
                            return '手动新增';
                        }
                    }
                },

                {title: '创建日期', field: 'filedate', align: 'center',width:200},

                {title: '是否入库', field: 'isconfirm', align: 'center',width:200,templet: function (res) {
                        if (res.isconfirm == '0') {
                            return '否';
                        } else {
                            return '是';
                        }
                    }
                },
                {title: '入库确认时间', field: 'confirmdate', align: 'center', width: 200},
                {title: '文档操作', toolbar: '#infoProjectbudgetJsfile-bar', align: 'center',width:200, fixed: 'right'},
                {title: '操作', toolbar: '#infoProjectbudgetJs-bar', align: 'center',width:100, fixed: 'right'}
            ]
        ]

        //table表单列表
        table.render({
            elem: '#infoProjectbudgetJs-table',
            url: MODULE_PATH + 'listin',
            page: true,
            method: 'get',
            cols: cols,
            skin: 'line',
            toolbar: '#infoProjectbudgetJs-toolbar',
            defaultToolbar: [{
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }],
            where: {'isconfirm': 1},
            done: function (res) {
                uploadBaseSingle();
                uploadYkSingle();
            }
        });

        //table图标事件绑定
        table.on('tool(infoProjectbudgetJs-table)', function (obj) {
            if (obj.event === 'remove') {
                window.remove(obj);
            } else if (obj.event === 'edit') {
                window.edit(obj);
            }
        });

        //table工具栏绑定
        table.on('toolbar(infoProjectbudgetJs-table)', function (obj) {
            if (obj.event === 'add') {
                window.add();
            } else if (obj.event === 'refresh') {
                window.refresh();
            } else if (obj.event === 'batchRemove') {
                window.batchRemove(obj);
            } else if (obj.event === 'import') {
                window.import(obj);
            }
        });

        //查询按钮绑定
        form.on('submit(infoProjectbudgetJs-query)', function (data) {
            table.reload('infoProjectbudgetJs-table', {where: data.field})
            return false;
        });


        //添加
        window.add = function () {
            layer.open({
                type: 2,
                title: '新增',
                shade: 0.1,
                area: ['50%', '80%'],
                content: MODULE_PATH + 'add'
            });
        }
        //修改
        window.edit = function (obj) {
            layer.open({
                type: 2,
                title: '修改',
                shade: 0.1,
                area: ['50%', '80%'],
                content: MODULE_PATH + 'edit/' + obj.data['id']
            });
        }
        //删除
        window.remove = function (obj) {
            layer.confirm('确定要删除该数据', {icon: 3, title: '提示'}, function (index) {
                layer.close(index);
                var loading = layer.load();
                $.ajax({
                    url: MODULE_PATH + "remove?ids=" + obj.data['id'],
                    dataType: 'json',
                    type: 'delete',
                    success: function (result) {
                        layer.close(loading);
                        if (result.code == 200) {
                            layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                                obj.del();
                            });
                        } else {
                            layer.msg(result.msg, {icon: 2, time: 1000});
                        }
                    }
                })
            });
        }

        //批量删除
        window.batchRemove = function (obj) {
            var data = table.checkStatus(obj.config.id).data;
            if (data.length === 0) {
                layer.msg("未选中数据", {icon: 3, time: 1000});
                return false;
            }
            var ids = "";
            for (var i = 0; i < data.length; i++) {
                ids += data[i].id + ",";
            }
            ids = ids.substr(0, ids.length - 1);
            layer.confirm('确定要删除这些数据', {icon: 3, title: '提示'}, function (index) {
                layer.close(index);
                var loading = layer.load();
                $.ajax({
                    url: MODULE_PATH + "remove?ids=" + ids,
                    dataType: 'json',
                    type: 'delete',
                    success: function (result) {
                        layer.close(loading);
                        if (result.code == 200) {
                            layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                                table.reload('infoProjectbudgetJs-table');
                            });
                        } else {
                            layer.msg(result.msg, {icon: 2, time: 1000});
                        }
                    }
                })
            });
        }
        //刷新按钮
        window.refresh = function () {
            table.reload('infoProjectbudgetJs-table');
        }

        function uploadBaseSingle() {
            upload.render({
                elem: '#uploadFile',
                url: MODULE_PATH + 'uploadBaseSingle',
                exts: 'xls|xlsx',
                choose: function (obj) {
                    // $('#uploadFileAction').click()
                    showLoad();
                },
                before: function (obj) {
                    this.data = {
                        'type': 1,
                    };
                },
                done: function (res) {
                    closeLoad(showLoad());//回调成功后关闭动画
                    if (res.code == 0) {
                        layer.msg(res.msg, {icon: 1, time: 5000});
                        table.reload('infoProjectbudgetJs-table')
                    } else {
                        layer.msg(res.msg, {icon: 2, time: 5000});
                    }
                },
                error: function (err) {
                    layer.alert('导入出现异常', {icon: 2});
                }
            });
        }

        function uploadYkSingle() {
            upload.render({
                elem: '#uploadFileYk',
                url: MODULE_PATH + 'uploadBaseSingle',
                exts: 'xls|xlsx',
                choose: function (obj) {
                    // $('#uploadFileAction').click()
                    showLoad();
                },
                before: function (obj) {
                    this.data = {
                        'type': 2,
                    };
                },
                done: function (res) {
                    closeLoad(showLoad());//回调成功后关闭动画
                    if (res.code == 0) {
                        layer.msg(res.msg, {icon: 1, time: 5000});
                        table.reload('infoProjectbudgetJs-table')

                    } else {
                        layer.msg(res.msg, {icon: 2, time: 5000});
                    }
                },
                error: function (err) {
                    layer.alert('导入出现异常', {icon: 2});
                }
            });
        }

        function showLoad() {
            return layer.msg('数据导入中，请耐心等待...', { icon: 6, shade: [0.5, '#f5f5f5'], scrollbar: false, offset: 'auto', time: 1000000 });
        }

        function closeLoad(index) {
            layer.close(index);
        }

        //材料模版 -d为id
        window.materialStencils = function (d) {
            //下载连接
            var index = layer.open({
                type: 2,
                title: '概算书PDF在线预览',
                shade: 0.1,
                area: ['1300px', '650px'],
                content: MODULE_PATH_FILE + 'fileview/' + d
            });
        }

        //下载概算书 -d为id
        window.downloadExcel = function (d) {
            //下载连接
            var index = layer.open({
                type: 2,
                title: '概算书下载',
                shade: 0.1,
                area: ['1300px', '650px'],
                content: MODULE_PATH_FILE + 'templatedownload/' + d
            });
        }

        //上传概算书（针对手动新增） -d为id
        window.uploadExcel = function (createtype, id) {
            if (createtype == 1){
                layer.alert('改数据非手工新增，无法补传概算书', {icon: 2});
                return false;
            }
            //下载连接
            var index = layer.open({
                type: 2,
                title: '上传概算书',
                shade: 0.1,
                area: ['1300px', '650px'],
                content: MODULE_PATH_FILE + 'uploadExcel/' + id+'/'+3
            });
        }

        window.import = function (obj) {
            var data = table.checkStatus(obj.config.id).data;
            if (data.length === 0) {
                layer.msg("未选中数据", {icon: 3, time: 1000});
                return false;
            }
            var ids = "";
            for (var i = 0; i < data.length; i++) {
                ids += data[i].id + ",";
            }
            ids = ids.substr(0, ids.length - 1);
            layer.confirm('确定要对这些数据进行入库操作', {icon: 3, title: '提示'}, function (index) {
                layer.close(index);
                var loading = layer.load();
                $.ajax({
                    url: MODULE_PATH + "import?ids=" + ids,
                    dataType: 'json',
                    type: 'post',
                    success: function (result) {
                        layer.close(loading);
                        if (result.code == 200) {
                            layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                                table.reload('infoProjectbudgetJs-table');
                            });
                        } else {
                            layer.msg(result.msg, {icon: 2, time: 1000});
                        }
                    }
                })
            });
        }

        //导出
        form.on('submit(export)', function (data) {
            var now = getnow();
            var url = rootPath + '/AgencyStyleExportController/agencyStyleExport4proJs?isconfirm='+ 1
            downloadFile(url,"结算环节工程概算导入(已入库)台账"+now+".xls");
        });

        function getnow(){
            var myDate = new Date();	//创建Date对象
            var Y = myDate.getFullYear();   //获取当前完整年份
            var M = myDate.getMonth() + 1;  //获取当前月份
            var D = myDate.getDate();   //获取当前日1-31
            var H = myDate.getHours();  //获取当前小时
            var i = myDate.getMinutes();    //获取当前分钟
            var s = myDate.getSeconds();    //获取当前秒数
            // 月份不足10补0
            if(M < 10){
                M = '0' + M;
            }
            // 日不足10补0
            if(D < 10){
                D = '0' + D;
            }
            // 小时不足10补0
            if(H < 10){
                H = '0' + H;
            }
            // 分钟不足10补0
            if(i < 10){
                i = '0' + i;
            }
            // 秒数不足10补0
            if(s < 10){
                s = '0' +s;
            }
            // 拼接日期分隔符根据自己的需要来修改
            var nowDate = M+'月'+D+'日 '+H+'时'+i+'分'+s+'秒';
            return nowDate;
        }
    })


</script>
</html>